home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcl / src-16f.lha / compiler / node.lisp < prev    next >
Encoding:
Text File  |  1992-02-23  |  47.7 KB  |  1,258 lines

  1. ;;; -*- Package: C; Log: C.Log -*-
  2. ;;;
  3. ;;; **********************************************************************
  4. ;;; This code was written as part of the CMU Common Lisp project at
  5. ;;; Carnegie Mellon University, and has been placed in the public domain.
  6. ;;; If you want to use this code or any part of CMU Common Lisp, please contact
  7. ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
  8. ;;;
  9. (ext:file-comment
  10.   "$Header: node.lisp,v 1.23 92/02/23 17:43:45 ram Exp $")
  11. ;;;
  12. ;;; **********************************************************************
  13. ;;;
  14. ;;;    Structures for the first intermediate representation in the compiler,
  15. ;;; IR1.
  16. ;;;
  17. ;;; Written by Rob MacLachlan
  18. ;;;
  19. (in-package 'c)
  20.  
  21. (export '(component component-info))
  22.  
  23. ;;; Defvars for these variables appear later.
  24. (proclaim '(special *current-path* *lexical-environment* *current-component*
  25.             *default-cookie* *default-interface-cookie*))
  26.   
  27.  
  28. (proclaim '(inline internal-make-lexenv))
  29.  
  30. ;;; The LEXENV represents the lexical environment used for IR1 conversion.
  31. ;;;
  32. (defstruct (lexenv
  33.         (:constructor make-null-environment ())
  34.         (:constructor internal-make-lexenv
  35.               (functions variables blocks tags type-restrictions
  36.                      inlines lambda cleanup cookie
  37.                      interface-cookie options)))
  38.   ;;
  39.   ;; Alist (name . what), where What is either a Functional (a local function)
  40.   ;; or a list (MACRO . <function>) (a local macro, with the specifier
  41.   ;; expander.)    Note that Name may be a (SETF <name>) function.
  42.   (functions nil :type list)
  43.   ;;
  44.   ;; An alist translating variable names to Leaf structures.  A special binding
  45.   ;; is indicated by a :Special Global-Var leaf.  Each special binding within
  46.   ;; the code gets a distinct leaf structure, as does the current "global"
  47.   ;; value on entry to the code compiled.  (locally (special ...)) is handled
  48.   ;; by adding the most recent special binding to the front of the list.
  49.   ;;
  50.   ;; If the CDR is (MACRO . <exp>), then <exp> is the expansion of a symbol
  51.   ;; macro.
  52.   ;;
  53.   ;; The value can also be a CT-A-VAL structure, representing an Alien
  54.   ;; variable.
  55.   (variables nil :type list)
  56.   ;;
  57.   ;; Blocks and Tags are alists from block and go-tag names to 2-lists of the
  58.   ;; form (<entry> <continuation>), where <continuation> is the continuation to
  59.   ;; exit to, and <entry> is the corresponding Entry node.
  60.   (blocks nil :type list)
  61.   (tags nil :type list)
  62.   ;;
  63.   ;; An alist (Thing . CType) which is used to keep track of "pervasive" type
  64.   ;; declarations.  When Thing is a leaf, this is for type declarations that
  65.   ;; pertain to the type in a syntactic extent which does not correspond to a
  66.   ;; binding of the affected name.  When Thing is a continuation, this is used
  67.   ;; to track the innermost THE type declaration.
  68.   (type-restrictions nil :type list)
  69.   ;;
  70.   ;; An alist (Leaf . Inlinep) describing local inline declarations.
  71.   (inlines nil :type list)
  72.   ;;
  73.   ;; The lexically enclosing lambda, if any.
  74.   (lambda nil :type (or clambda null))
  75.   ;;
  76.   ;; The lexically enclosing cleanup, or NIL if none enclosing within Lambda.
  77.   (cleanup nil :type (or cleanup null))
  78.   ;;
  79.   ;; The representation of the current OPTIMIZE policy. 
  80.   (cookie *default-cookie* :type cookie)
  81.   ;;
  82.   ;; The policy that takes effect in XEPs and related syntax parsing functions.
  83.   ;; Slots in this cookie may be null to indicate that the normal value in
  84.   ;; effect.
  85.   (interface-cookie *default-interface-cookie* :type cookie)
  86.   ;;
  87.   ;; AList of random options that are associated with the lexical
  88.   ;; environment.  They can be established with COMPILER-OPTION-BIND.
  89.   (options nil :type list))
  90.  
  91.  
  92. ;;; The front-end data structure (IR1) is composed of nodes and continuations.
  93. ;;; The general idea is that continuations contain top-down information and
  94. ;;; nodes contain bottom-up, derived information.  A continuation represents a
  95. ;;; place in the code, while a node represents code that does something.
  96. ;;;
  97. ;;; This representation is more of a flow-graph than an augmented syntax tree.
  98. ;;; The evaluation order is explicitly represented in the linkage by
  99. ;;; continuations, rather than being implicit in the nodes which receive the
  100. ;;; the results of evaluation.  This allows us to decouple the flow of results
  101. ;;; from the flow of control.  A continuation represents both, but the
  102. ;;; continuation can represent the case of a discarded result by having no
  103. ;;; DEST. 
  104.  
  105. (defstruct (continuation
  106.         (:print-function %print-continuation)
  107.         (:make-load-form-fun :ignore-it)
  108.         (:constructor really-make-continuation (&optional dest)))
  109.   ;;
  110.   ;; An indication of the way that this continuation is currently used:
  111.   ;;
  112.   ;; :Unused
  113.   ;;        A continuation for which all control-related slots have the default
  114.   ;;        values.  A continuation is unused during IR1 conversion until it is
  115.   ;;        assigned a block, and may be also be temporarily unused during
  116.   ;;        later manipulations of IR1.  In a consistent state there should
  117.   ;;        never be any mention of :Unused continuations.  Next can have a
  118.   ;;        non-null value if the next node has already been determined.
  119.   ;;
  120.   ;; :Deleted
  121.   ;;        A continuation that has been deleted from IR1.  Any pointers into
  122.   ;;        IR1 are cleared.  There are two conditions under which a deleted
  123.   ;;        continuation may appear in code:
  124.   ;;         -- The Cont of the Last node in a block may be a deleted
  125.   ;;            continuation when the original receiver of the continuation's
  126.   ;;            value was deleted.  Note that Dest in a deleted continuation is
  127.   ;;            null, so it is easy to know not to attempt delivering any
  128.   ;;            values to the continuation.
  129.   ;;         -- Unreachable code that hasn't been deleted yet may receive
  130.   ;;            deleted continuations.  All such code will be in blocks that
  131.   ;;            have DELETE-P set.  All unreachable code is deleted by control
  132.   ;;            optimization, so the backend doesn't have to worry about this.
  133.   ;;
  134.   ;; :Block-Start
  135.   ;;        The continuation that is the Start of Block.  This is the only kind
  136.   ;;        of continuation that can have more than one use.  The Block's
  137.   ;;        Start-Uses is a list of all the uses.
  138.   ;;
  139.   ;; :Deleted-Block-Start
  140.   ;;        Like :Block-Start, but Block has been deleted.  A block starting
  141.   ;;        continuation is made into a deleted block start when the block is
  142.   ;;        deleted, but the continuation still may have value semantics.
  143.   ;;        Since there isn't any code left, next is null.
  144.   ;;
  145.   ;; :Inside-Block
  146.   ;;        A continuation that is the Cont of some node in Block.
  147.   ;;
  148.   (kind :unused :type (member :unused :deleted :inside-block :block-start
  149.                   :deleted-block-start))
  150.   ;;
  151.   ;; The node which receives this value, if any.  In a deleted continuation,
  152.   ;; this is null even though the node that receives this continuation may not
  153.   ;; yet be deleted.
  154.   (dest nil :type (or node null))
  155.   ;;
  156.   ;; If this is a Node, then it is the node which is to be evaluated next.
  157.   ;; This is always null in :Deleted and :Unused continuations, and will be
  158.   ;; null in a :Inside-Block continuation when this is the CONT of the LAST.
  159.   (next nil :type (or node null))
  160.   ;;
  161.   ;; An assertion on the type of this continuation's value.
  162.   (asserted-type *wild-type* :type ctype)
  163.   ;;
  164.   ;; Cached type of this contiuation's value.  If NIL, then this must be
  165.   ;; recomputed: see Continuation-Derived-Type.
  166.   (%derived-type nil :type (or ctype null))
  167.   ;;
  168.   ;; Node where this continuation is used, if unique.  This is always null in
  169.   ;; :Deleted and :Unused continuations, and is never null in :Inside-Block
  170.   ;; continuations.  In a :Block-Start contiuation, the Block's Start-Uses
  171.   ;; indicate whether NIL means no uses or more than one use.
  172.   (use nil :type (or node null))
  173.   ;;
  174.   ;; Basic block this continuation is in.  This is null only in :Deleted and
  175.   ;; :Unused continuations.  Note that blocks that are unreachable but still in
  176.   ;; the DFO may receive deleted continuations, so it isn't o.k. to assume that
  177.   ;; any random continuation that you pick up out of its Dest node has a Block.
  178.   (block nil :type (or cblock null))
  179.   ;;
  180.   ;; Set to true when something about this continuation's value has changed.
  181.   ;; See Reoptimize-Continuation.  This provides a way for IR1 optimize to
  182.   ;; determine which operands to a node have changed.  If the optimizer for
  183.   ;; this node type doesn't care, it can elect not to clear this flag.
  184.   (reoptimize t :type boolean)
  185.   ;;
  186.   ;; An indication of what we have proven about how this contination's type
  187.   ;; assertion is satisfied:
  188.   ;; 
  189.   ;; NIL
  190.   ;;    No type check is necessary (proven type is a subtype of the assertion.)
  191.   ;;
  192.   ;; T
  193.   ;;    A type check is needed.
  194.   ;;
  195.   ;; :DELETED
  196.   ;;    Don't do a type check, but believe (intersect) the assertion.  A T
  197.   ;;    check can be changed to :DELETED if we somehow prove the check is
  198.   ;;    unnecessary, or if we eliminate it through a policy decision.
  199.   ;;
  200.   ;; :NO-CHECK
  201.   ;;    Type check generation sets the slot to this if a check is called for,
  202.   ;;    but it believes it has proven that the check won't be done for
  203.   ;;    policy reasons or because a safe implementation will be used.  In the
  204.   ;;    latter case, LTN must ensure that a safe implementation *is* be used.
  205.   ;;
  206.   ;; :ERROR
  207.   ;;    There is a compile-time type error in some use of this continuation.  A
  208.   ;;    type check should still be generated, but be careful.
  209.   ;;
  210.   ;; This is computed lazily by CONTINUATION-DERIVED-TYPE, so use
  211.   ;; CONTINUATION-TYPE-CHECK instead of the %'ed slot accessor.
  212.   ;;
  213.   (%type-check t :type (member t nil :deleted :no-check :error))
  214.   ;;
  215.   ;; Something or other that the back end annotates this continuation with.
  216.   (info nil))
  217.  
  218. (defun %print-continuation (s stream d)
  219.   (declare (ignore d))
  220.   (format stream "#<Continuation c~D>" (cont-num s)))
  221.  
  222.  
  223. (defstruct node
  224.   ;;
  225.   ;; The bottom-up derived type for this node.  This does not take into
  226.   ;; consideration output type assertions on this node (actually on its CONT).
  227.   (derived-type *wild-type* :type ctype)
  228.   ;;
  229.   ;; True if this node needs to be optimized.  This is set to true whenever
  230.   ;; something changes about the value of a continuation whose DEST is this
  231.   ;; node.
  232.   (reoptimize t :type boolean)
  233.   ;;
  234.   ;; The continuation which receives the value of this node.  This also
  235.   ;; indicates what we do controlwise after evaluating this node.  This may be
  236.   ;; null during IR1 conversion.
  237.   (cont nil :type (or continuation null))
  238.   ;; 
  239.   ;; The continuation that this node is the next of.  This is null during
  240.   ;; IR1 conversion when we haven't linked the node in yet or in nodes that
  241.   ;; have been deleted from the IR1 by UNLINK-NODE.
  242.   (prev nil :type (or continuation null))
  243.   ;;
  244.   ;; The lexical environment this node was converted in.
  245.   (lexenv *lexical-environment* :type lexenv)
  246.   ;;
  247.   ;; A representation of the source code responsible for generating this node.
  248.   ;; 
  249.   ;; For a form introduced by compilation (does not appear in the original
  250.   ;; source), the path begins with a list of all the enclosing introduced
  251.   ;; forms.  This list is from the inside out, with the form immediately
  252.   ;; responsible for this node at the head of the list.
  253.   ;;
  254.   ;; Following the introduced forms is a representation of the location of the
  255.   ;; enclosing original source form.  This transition is indicated by the magic
  256.   ;; ORIGINAL-SOURCE-START marker.  The first element of the orignal source is
  257.   ;; the "form number", which is the ordinal number of this form in a
  258.   ;; depth-first, left-to-right walk of the truly top-level form in which this
  259.   ;; appears.
  260.   ;;
  261.   ;; Following is a list of integers describing the path taken through the
  262.   ;; source to get to this point:
  263.   ;;     (k l m ...) => (nth k (nth l (nth m ...)))
  264.   ;; 
  265.   ;; The last element in the list is the top-level form number, which is the
  266.   ;; ordinal number (in this call to the compiler) of the truly top-level form
  267.   ;; containing the orignal source.
  268.   (source-path *current-path* :type list)
  269.   ;;
  270.   ;; If this node is in a tail-recursive position, then this is set to T.  At
  271.   ;; the end of IR1 (in environment analysis) this is computed for all nodes
  272.   ;; (after cleanup code has been emitted).  Before then, a non-null value
  273.   ;; indicates that IR1 optimization has converted a tail local call to a
  274.   ;; direct transfer.
  275.   ;;
  276.   ;; If the back-end breaks tail-recursion for some reason, then it can null
  277.   ;; out this slot.
  278.   (tail-p nil :type boolean))
  279.  
  280.  
  281. ;;; Flags that are used to indicate various things about a block, such as what
  282. ;;; optimizations need to be done on it:
  283. ;;; -- REOPTIMIZE is set when something interesting happens the uses of a
  284. ;;;    continuation whose Dest is in this block.  This indicates that the
  285. ;;;    value-driven (forward) IR1 optimizations should be done on this block.
  286. ;;; -- FLUSH-P is set when code in this block becomes potentially flushable,
  287. ;;;    usually due to a continuation's DEST becoming null.
  288. ;;; -- TYPE-CHECK is true when the type check phase should be run on this
  289. ;;;    block.  IR1 optimize can introduce new blocks after type check has
  290. ;;;    already run.  We need to check these blocks, but there is no point in
  291. ;;;    checking blocks we have already checked.
  292. ;;; -- DELETE-P is true when this block is used to indicate that this block
  293. ;;;    has been determined to be unreachable and should be deleted.  IR1
  294. ;;;    phases should not attempt to  examine or modify blocks with DELETE-P
  295. ;;;    set, since they may:
  296. ;;;     - be in the process of being deleted, or
  297. ;;;     - have no successors, or
  298. ;;;     - receive :DELETED continuations.
  299. ;;; -- TYPE-ASSERTED, TEST-MODIFIED
  300. ;;;    These flags are used to indicate that something in this block might be
  301. ;;;    of interest to constraint propagation.  TYPE-ASSERTED is set when a
  302. ;;;    continuation type assertion is strengthened.  TEST-MODIFIED is set
  303. ;;;    whenever the test for the ending IF has changed (may be true when there
  304. ;;;    is no IF.)
  305. ;;;
  306. (def-boolean-attribute block
  307.   reoptimize flush-p type-check delete-p type-asserted test-modified)
  308.  
  309. (macrolet ((frob (slot)
  310.          `(defmacro ,(symbolicate "BLOCK-" slot) (block)
  311.         `(block-attributep (block-flags ,block) ,',slot))))
  312.   (frob reoptimize)
  313.   (frob flush-p)
  314.   (frob type-check)
  315.   (frob delete-p)
  316.   (frob type-asserted)
  317.   (frob test-modified))
  318.   
  319.  
  320. ;;; The CBlock structure represents a basic block.  We include SSet-Element so
  321. ;;; that we can have sets of blocks.  Initially the SSet-Element-Number is
  322. ;;; null, but we number in reverse DFO before we do any set operations.
  323. ;;;
  324. (defstruct (cblock (:print-function %print-block)
  325.            (:include sset-element)
  326.            (:constructor really-make-block (start))
  327.            (:constructor make-block-key)
  328.            (:conc-name block-)
  329.            (:predicate block-p)
  330.            (:copier copy-block))
  331.   ;;
  332.   ;; A list of all the blocks that are predecessors/successors of this block.
  333.   ;; In well-formed IR1, most blocks will have one successors.  The only
  334.   ;; exceptions are:
  335.   ;;  1] component head blocks (any number)
  336.   ;;  2] blocks ending in an IF (1 or 2)
  337.   ;;  3] blocks with DELETE-P set (zero)
  338.   (pred nil :type list)
  339.   (succ nil :type list)
  340.   ;;
  341.   ;; The continuation which heads this block (either a :Block-Start or
  342.   ;; :Deleted-Block-Start.)  Null when we haven't made the start continuation
  343.   ;; yet (and in the dummy component head and tail blocks.)
  344.   (start nil :type (or continuation null))
  345.   ;;
  346.   ;; A list of all the nodes that have Start as their Cont.
  347.   (start-uses nil :type list)
  348.   ;;
  349.   ;; The last node in this block.  This is null when we are in the process of
  350.   ;; building a block (and in the dummy component head and tail blocks.)
  351.   (last nil :type (or node null))
  352.   ;;
  353.   ;; The forward and backward links in the depth-first ordering of the blocks.
  354.   ;; These slots are null at beginning/end.
  355.   (next nil :type (or null cblock))
  356.   (prev nil :type (or null cblock))
  357.   ;;
  358.   ;; This block's attributes: see above.
  359.   (flags (block-attributes reoptimize flush-p type-check type-asserted
  360.                test-modified)
  361.      :type attributes)
  362.   ;;
  363.   ;; Some sets used by constraint propagation.
  364.   (kill nil)
  365.   (gen nil)
  366.   (in nil)
  367.   (out nil)
  368.   ;;
  369.   ;; The component this block is in.  Null temporarily during IR1 conversion
  370.   ;; and in deleted blocks.
  371.   (component *current-component* :type (or component null))
  372.   ;;
  373.   ;; A flag used by various graph-walking code to determine whether this block
  374.   ;; has been processed already or what.  We make this initially NIL so that
  375.   ;; Find-Initial-DFO doesn't have to scan the entire initial component just to
  376.   ;; clear the flags.
  377.   (flag nil)
  378.   ;;
  379.   ;; Some kind of info used by the back end.
  380.   (info nil)
  381.   ;;
  382.   ;; If true, then constraints that hold in this block and its successors by
  383.   ;; merit of being tested by its IF predecessor.
  384.   (test-constraint nil :type (or sset null)))
  385.  
  386.  
  387. (defun %print-block (s stream d)
  388.   (declare (ignore d))
  389.   (format stream "#<Block ~X, Start = c~D>" (system:%primitive make-fixnum s)
  390.       (cont-num (block-start s))))
  391.  
  392.  
  393. ;;; The Component structure provides a handle on a connected piece of the flow
  394. ;;; graph.  Most of the passes in the compiler operate on components rather
  395. ;;; than on the entire flow graph.
  396. ;;;
  397. (defstruct (component (:print-function %print-component))
  398.   ;;
  399.   ;; The kind of component:
  400.   ;; 
  401.   ;; NIL
  402.   ;;     An ordinary component, containing arbitrary code.
  403.   ;;
  404.   ;; :Top-Level
  405.   ;;     A component containing only load-time code.
  406.   ;;
  407.   ;; :Initial
  408.   ;;     The result of initial IR1 conversion, on which component analysis has
  409.   ;;     not been done.
  410.   ;;
  411.   ;; :Deleted
  412.   ;;     Debris left over from component analysis.
  413.   ;;
  414.   (kind nil :type (member nil :top-level :initial :deleted))
  415.   ;;
  416.   ;; The blocks that are the dummy head and tail of the DFO.  Entry/exit points
  417.   ;; have these blocks as their predecessors/successors.  Null temporarily.
  418.   ;; The start and return from each non-deleted function is linked to the
  419.   ;; component head and tail.  Until environment analysis links NLX entry stubs
  420.   ;; to the component head, every successor of the head is a function start
  421.   ;; (i.e. begins with a Bind node.)
  422.   (head nil :type (or null cblock))
  423.   (tail nil :type (or null cblock))
  424.   ;;
  425.   ;; A list of the CLambda structures for all functions in this component.
  426.   ;; Optional-Dispatches are represented only by their XEP and other associated
  427.   ;; lambdas.  This doesn't contain any deleted or let lambdas.
  428.   (lambdas () :type list)
  429.   ;;
  430.   ;; A list of Functional structures for functions that are newly converted,
  431.   ;; and haven't been local-call analyzed yet.  Unanalyzed functions aren't in
  432.   ;; the Lambdas list.  Functions are moved into the Lambdas as they are
  433.   ;; analysed.
  434.   (new-functions () :type list)
  435.   ;;
  436.   ;; If true, then there is stuff in this component that could benefit from
  437.   ;; further IR1 optimization.
  438.   (reoptimize t :type boolean)
  439.   ;;
  440.   ;; If true, then the control flow in this component was messed up by IR1
  441.   ;; optimizations.  The DFO should be recomputed.
  442.   (reanalyze nil :type boolean)
  443.   ;;
  444.   ;; String that is some sort of name for the code in this component.
  445.   (name "<unknown>" :type simple-string)
  446.   ;;
  447.   ;; Some kind of info used by the back end.
  448.   (info nil)
  449.   ;;
  450.   ;; The Source-Info structure describing where this component was compiled
  451.   ;; from.
  452.   (source-info *source-info* :type source-info))
  453.  
  454. (defprinter component
  455.   name
  456.   (reanalyze :test reanalyze))
  457.   
  458.  
  459. ;;; The Cleanup structure represents some dynamic binding action.  Blocks are
  460. ;;; annotated with the current cleanup so that dynamic bindings can be removed
  461. ;;; when control is transferred out of the binding environment.  We arrange for
  462. ;;; changes in dynamic bindings to happen at block boundaries, so that cleanup
  463. ;;; code may easily be inserted.  The "mess-up" action is explictly represented
  464. ;;; by a funny function call or Entry node.
  465. ;;;
  466. ;;; We guarantee that cleanups only need to be done at block boundries by
  467. ;;; requiring that the exit continuations initially head their blocks, and then
  468. ;;; by not merging blocks when there is a cleanup change.
  469. ;;;
  470. (defstruct (cleanup (:print-function %print-cleanup))
  471.   ;;
  472.   ;; The kind of thing that has to be cleaned up.
  473.   (kind (required-argument)
  474.     :type (member :special-bind :catch :unwind-protect :block :tagbody))
  475.   ;;
  476.   ;; The node that messes things up.  This is the last node in the
  477.   ;; non-messed-up environment.  Null only temporarily.  This could be deleted
  478.   ;; due to unreachability.
  479.   (mess-up nil :type (or node null))
  480.   ;;
  481.   ;; A list of all the NLX-Info structures whose NLX-Info-Cleanup is this
  482.   ;; cleanup.  This is filled in by environment analysis.
  483.   (nlx-info nil :type list))
  484.  
  485. (defprinter cleanup
  486.   kind
  487.   mess-up
  488.   (nlx-info :test nlx-info))
  489.  
  490.  
  491. ;;; The Environment structure represents the result of Environment analysis.
  492. ;;;
  493. (defstruct (environment (:print-function %print-environment))
  494.   ;;
  495.   ;; The function that allocates this environment.
  496.   (function (required-argument) :type clambda)
  497.   ;;
  498.   ;; A list of all the Lambdas that allocate variables in this environment.
  499.   (lambdas nil :type list)
  500.   ;;
  501.   ;; A list of all the lambda-vars and NLX-Infos needed from enclosing
  502.   ;; environments by code in this environment.
  503.   (closure nil :type list)
  504.   ;;
  505.   ;; A list of NLX-Info structures describing all the non-local exits into this
  506.   ;; environment.
  507.   (nlx-info nil :type list)
  508.   ;;
  509.   ;; Some kind of info used by the back end.
  510.   (info nil))
  511.  
  512. (defprinter environment
  513.   function
  514.   (closure :test closure)
  515.   (nlx-info :test nlx-info))
  516.  
  517.  
  518. ;;; The Tail-Set structure is used to accmumlate information about
  519. ;;; tail-recursive local calls.  The "tail set" is effectively the transitive
  520. ;;; closure of the "is called tail-recursively by" relation.
  521. ;;;
  522. ;;; All functions in the same tail set share the same Tail-Set structure.
  523. ;;; Initially each function has its own Tail-Set, but when IR1-OPTIMIZE-RETURN
  524. ;;; notices a tail local call, it joins the tail sets of the called function
  525. ;;; and the calling function.
  526. ;;;
  527. ;;; The tail set is somewhat approximate, because it is too early to be sure
  528. ;;; which calls will be TR.  Any call that *might* end up TR causes tail-set
  529. ;;; merging.
  530. ;;;
  531. (defstruct (tail-set
  532.         (:print-function %print-tail-set))
  533.   ;;
  534.   ;; A list of all the lambdas in this tail set.
  535.   (functions nil :type list)
  536.   ;;
  537.   ;; Our current best guess of the type returned by these functions.  This is
  538.   ;; the union across all the functions of the return node's Result-Type.
  539.   ;; excluding local calls.
  540.   (type *wild-type* :type ctype)
  541.   ;;
  542.   ;; Some info used by the back end.
  543.   (info nil))
  544.  
  545. (defprinter tail-set
  546.   functions
  547.   type
  548.   (info :test info))
  549.  
  550.  
  551. ;;; The NLX-Info structure is used to collect various information about
  552. ;;; non-local exits.  This is effectively an annotation on the Continuation,
  553. ;;; although it is accessed by searching in the Environment-Nlx-Info.
  554. ;;;
  555. (defstruct (nlx-info
  556.         (:print-function %print-nlx-info)
  557.         (:make-load-form-fun :ignore-it))
  558.   ;;
  559.   ;; The cleanup associated with this exit.  In a catch or unwind-protect, this
  560.   ;; is the :Catch or :Unwind-Protect cleanup, and not the cleanup for the
  561.   ;; escape block.  The Cleanup-Kind of this thus provides a good indication of
  562.   ;; what kind of exit is being done.
  563.   (cleanup (required-argument) :type cleanup)
  564.   ;;
  565.   ;; The continuation exited to (the CONT of the EXIT nodes.)  If this exit is
  566.   ;; from an escape function (CATCH or UNWIND-PROTECT), then environment
  567.   ;; analysis deletes the escape function and instead has the %NLX-ENTRY use
  568.   ;; this continuation.
  569.   ;;
  570.   ;; This slot is primarily an indication of where this exit delivers its
  571.   ;; values to (if any), but it is also used as a sort of name to allow us to
  572.   ;; find the NLX-Info that corresponds to a given exit.  For this purpose, the
  573.   ;; Entry must also be used to disambiguate, since exits to different places
  574.   ;; may deliver their result to the same continuation.
  575.   (continuation (required-argument) :type continuation)
  576.   ;;
  577.   ;; The entry stub inserted by environment analysis.  This is a block
  578.   ;; containing a call to the %NLX-Entry funny function that has the original
  579.   ;; exit destination as its successor.  Null only temporarily.
  580.   (target nil :type (or cblock null))
  581.   ;;
  582.   ;; Some kind of info used by the back end.
  583.   info)
  584.  
  585. (defprinter nlx-info
  586.   continuation
  587.   target
  588.   info)
  589.  
  590.  
  591. ;;; Leaves:
  592. ;;;
  593. ;;;    Variables, constants and functions are all represented by Leaf
  594. ;;; structures.  A reference to a Leaf is indicated by a Ref node.  This allows
  595. ;;; us to easily substitute one for the other without actually hacking the flow
  596. ;;; graph.
  597.  
  598. (defstruct (leaf
  599.         (:make-load-form-fun :ignore-it))
  600.   ;;
  601.   ;; Some name for this leaf.  The exact significance of the name depends on
  602.   ;; what kind of leaf it is.  In a Lambda-Var or Global-Var, this is the
  603.   ;; symbol name of the variable.  In a functional that is from a DEFUN, this
  604.   ;; is the defined name.  In other functionals, this is a descriptive string.
  605.   (name nil :type t)
  606.   ;;
  607.   ;; The type which values of this leaf must have.
  608.   (type *universal-type* :type ctype)
  609.   ;;
  610.   ;; Where the Type information came from:
  611.   ;;  :declared, from a declaration.
  612.   ;;  :assumed, from uses of the object.
  613.   ;;  :defined, from examination of the definition.
  614.   (where-from :assumed :type (member :declared :assumed :defined))
  615.   ;;
  616.   ;; List of the Ref nodes for this leaf.
  617.   (refs () :type list)
  618.   ;;
  619.   ;; True if there was ever a Ref or Set node for this leaf.  This may be true
  620.   ;; when Refs and Sets are null, since code can be deleted.
  621.   (ever-used nil :type boolean)
  622.   ;;
  623.   ;; Some kind of info used by the back end.
  624.   (info nil))
  625.  
  626.  
  627. ;;; The Constant structure is used to represent known constant values.  If Name
  628. ;;; is not null, then it is the name of the named constant which this leaf
  629. ;;; corresponds to, otherwise this is an anonymous constant.
  630. ;;;
  631. (defstruct (constant (:include leaf)
  632.              (:print-function %print-constant))
  633.   ;;
  634.   ;; The value of the constant.
  635.   (value nil :type t))
  636.  
  637. (defprinter constant
  638.   (name :test name)
  639.   value)
  640.  
  641.   
  642. ;;; The Basic-Var structure represents information common to all variables
  643. ;;; which don't correspond to known local functions.
  644. ;;;
  645. (defstruct (basic-var (:include leaf))
  646.   ;;
  647.   ;; Lists of the set nodes for this variable.
  648.   (sets () :type list))
  649.  
  650.  
  651. ;;; The Global-Var structure represents a value hung off of the symbol Name.
  652. ;;; We use a :Constant Var when we know that the thing is a constant, but don't
  653. ;;; know what the value is at compile time.
  654. ;;;
  655. (defstruct (global-var (:include basic-var)
  656.                (:print-function %print-global-var))
  657.   ;;
  658.   ;; Kind of variable described.
  659.   (kind (required-argument)
  660.     :type (member :special :global-function :constant :global)))
  661.  
  662. (defprinter global-var
  663.   name
  664.   (type :test (not (eq type *universal-type*)))
  665.   (where-from :test (not (eq where-from :assumed)))
  666.   kind)
  667.  
  668.  
  669. ;;; The Slot-Accessor structure represents defstruct slot accessors.  It is a
  670. ;;; subtype of Global-Var to make it look more like a normal function.
  671. ;;;
  672. (defstruct (slot-accessor (:include global-var
  673.                     (where-from :defined)
  674.                     (kind :global-function))
  675.               (:print-function %print-slot-accessor))
  676.   ;;
  677.   ;; The description of the structure that this is an accessor for.
  678.   (for (required-argument) :type defstruct-description)
  679.   ;;
  680.   ;; The slot description of the slot.
  681.   (slot (required-argument) :type defstruct-slot-description))
  682.  
  683. (defprinter slot-accessor
  684.   name
  685.   for
  686.   slot)
  687.  
  688.  
  689.  
  690. ;;;; Function stuff:
  691.  
  692.  
  693. ;;; We default the Where-From and Type slots to :Defined and Function.  We
  694. ;;; don't normally manipulate function types for defined functions, but if
  695. ;;; someone wants to know, an approximation is there.
  696. ;;;
  697. (defstruct (functional (:include leaf
  698.                  (:where-from :defined)
  699.                  (:type (specifier-type 'function)))
  700.                (:print-function %print-functional))
  701.   ;;        
  702.   ;;        
  703.   ;;        
  704.   ;;
  705.   ;; Some information about how this function is used.  These values are
  706.   ;; meaningful:
  707.   ;;
  708.   ;;    Nil
  709.   ;;        An ordinary function, callable using local call.
  710.   ;;
  711.   ;;    :Let
  712.   ;;        A lambda that is used in only one local call, and has in effect
  713.   ;;        been substituted directly inline.  The return node is deleted, and
  714.   ;;        the result is computed with the actual result continuation for the
  715.   ;;        call.
  716.   ;;
  717.   ;;    :MV-Let
  718.   ;;        Similar to :Let, but the call is an MV-Call.
  719.   ;;
  720.   ;;    :Assignment
  721.   ;;        Similar to a let, but can have other than one call as long as there
  722.   ;;        is at most one non-tail call.
  723.   ;;
  724.   ;;    :Optional
  725.   ;;        A lambda that is an entry-point for an optional-dispatch.  Similar
  726.   ;;        to NIL, but requires greater caution, since local call analysis may
  727.   ;;        create new references to this function.  Also, the function cannot
  728.   ;;        be deleted even if it has *no* references.  The Optional-Dispatch
  729.   ;;        is in the LAMDBA-OPTIONAL-DISPATCH.
  730.   ;;
  731.   ;;    :External
  732.   ;;        An external entry point lambda.  The function it is an entry for is
  733.   ;;        in the Entry-Function.
  734.   ;;
  735.   ;;    :Top-Level
  736.   ;;        A top-level lambda, holding a compiled top-level form.  Compiled
  737.   ;;        very much like NIL, but provides an indication of top-level
  738.   ;;        context.  A top-level lambda should have *no* references.  Its
  739.   ;;        Entry-Function is a self-pointer.
  740.   ;;
  741.   ;;    :Top-Level-XEP
  742.   ;;        After a component is compiled, we clobber any top-level code
  743.   ;;        references to its non-closure XEPs with dummy FUNCTIONAL structures
  744.   ;;        having this kind.  This prevents the retained top-level code from
  745.   ;;        holding onto the IR for the code it references.
  746.   ;;
  747.   ;;    :Escape
  748.   ;;    :Cleanup
  749.   ;;        Special functions used internally by Catch and Unwind-Protect.
  750.   ;;        These are pretty much like a normal function (NIL), but are treated
  751.   ;;        specially by local call analysis and stuff.  Neither kind should
  752.   ;;        ever be given an XEP even though they appear as args to funny
  753.   ;;        functions.  An :Escape function is never actually called, and thus
  754.   ;;        doesn't need to have code generated for it.
  755.   ;;
  756.   ;;    :Deleted
  757.   ;;        This function has been found to be uncallable, and has been
  758.   ;;        marked for deletion.
  759.   ;;
  760.   (kind nil :type (member nil :optional :deleted :external :top-level :escape
  761.               :cleanup :let :mv-let :assignment
  762.               :top-level-xep))
  763.   ;;
  764.   ;; In a normal function, this is the external entry point (XEP) lambda for
  765.   ;; this function, if any.  Each function that is used other than in a local
  766.   ;; call has an XEP, and all of the non-local-call references are replaced
  767.   ;; with references to the XEP.
  768.   ;;
  769.   ;; In an XEP lambda (indicated by the :External kind), this is the function
  770.   ;; that the XEP is an entry-point for.  The body contains local calls to all
  771.   ;; the actual entry points in the function.  In a :Top-Level lambda (which is
  772.   ;; its own XEP) this is a self-pointer.
  773.   ;;
  774.   ;; With all other kinds, this is null.
  775.   (entry-function nil :type (or functional null))
  776.   ;;
  777.   ;; If we have a lambda that can be used as in inline expansion for this
  778.   ;; function, then this is it.  If there is no source-level lambda
  779.   ;; corresponding to this function then this is Null.
  780.   (inline-expansion nil :type list)
  781.   ;;
  782.   ;; The lexical environment that the inline-expansion should be converted in.
  783.   (lexenv *lexical-environment* :type lexenv)
  784.   ;;
  785.   ;; The original function or macro lambda list, or :UNSPECIFIED if this is a
  786.   ;; compiler created function.
  787.   (arg-documentation nil :type (or list (member :unspecified))))
  788.   
  789. (defprinter functional
  790.   name)
  791.  
  792.  
  793. ;;; The Lambda only deals with required lexical arguments.  Special, optional,
  794. ;;; keyword and rest arguments are handled by transforming into simpler stuff.
  795. ;;;
  796. (defstruct (clambda (:include functional)
  797.             (:print-function %print-lambda)
  798.             (:conc-name lambda-)
  799.             (:predicate lambda-p)
  800.             (:constructor make-lambda)
  801.             (:copier copy-lambda))
  802.   ;;
  803.   ;; List of lambda-var descriptors for args.
  804.   (vars nil :type list)
  805.   ;;
  806.   ;; If this function was ever a :OPTIONAL function (an entry-point for an
  807.   ;; optional-dispatch), then this is that optional-dispatch.  The optional
  808.   ;; dispatch will be :DELETED if this function is no longer :OPTIONAL.
  809.   (optional-dispatch nil :type (or optional-dispatch null))
  810.   ;;
  811.   ;; The Bind node for this Lambda.  This node marks the beginning of the
  812.   ;; lambda, and serves to explicitly represent the lambda binding semantics
  813.   ;; within the flow graph representation.  Null in deleted functions, and also
  814.   ;; in LETs where we deleted the call & bind (because there are no variables
  815.   ;; left), but have not yet actually deleted the lambda yet.
  816.   (bind nil :type (or bind null))
  817.   ;;
  818.   ;; The Return node for this Lambda, or NIL if it has been deleted.  This
  819.   ;; marks the end of the lambda, receiving the result of the body.  In a let,
  820.   ;; the return node is deleted, and the body delivers the value to the actual
  821.   ;; continuation.  The return may also be deleted if it is unreachable.
  822.   (return nil :type (or creturn null))
  823.   ;;
  824.   ;; If this is a let, then the Lambda whose Lets list we are in, otherwise
  825.   ;; this is a self-pointer.
  826.   (home nil :type (or clambda null))
  827.   ;;
  828.   ;; A list of all the all the lambdas that have been let-substituted in this
  829.   ;; lambda.  This is only non-null in lambdas that aren't lets.
  830.   (lets () :type list)
  831.   ;;
  832.   ;; A list of all the Entry nodes in this function and its lets.  Null an a
  833.   ;; let.
  834.   (entries () :type list)
  835.   ;;
  836.   ;; A list of all the functions directly called from this function (or one of
  837.   ;; its lets) using a non-let local call.
  838.   (calls () :type list)
  839.   ;;
  840.   ;; The Tail-Set that this lambda is in.  Null during creation and in let
  841.   ;; lambdas.
  842.   (tail-set nil :type (or tail-set null))
  843.   ;;
  844.   ;; The structure which represents the environment that this Function's
  845.   ;; variables are allocated in.  This is filled in by environment analysis.
  846.   ;; In a let, this is EQ to our home's environment.
  847.   (environment nil :type (or environment null))
  848.   ;;
  849.   ;; In a LET, this is the NODE-LEXENV of the combination node.  We retain it
  850.   ;; so that if the let is deleted (due to a lack of vars), we will still have
  851.   ;; caller's lexenv to figure out which cleanup is in effect.
  852.   (call-lexenv nil :type (or lexenv null)))
  853.  
  854. (defprinter lambda
  855.   name
  856.   (type :test (not (eq type *universal-type*)))
  857.   (where-from :test (not (eq where-from :assumed)))
  858.   (vars :prin1 (mapcar #'leaf-name vars)))
  859.  
  860.  
  861. ;;; The Optional-Dispatch leaf is used to represent hairy lambdas.  If is a
  862. ;;; Functional, like Lambda.  Each legal number of arguments has a function
  863. ;;; which is called when that number of arguments is passed.  The function is
  864. ;;; called with all the arguments actually passed.  If additional arguments are
  865. ;;; legal, then the LEXPR style More-Entry handles them.  The value returned by
  866. ;;; the function is the value which results from calling the Optional-Dispatch.
  867. ;;;
  868. ;;; The theory is that each entry-point function calls the next entry
  869. ;;; point tail-recursively, passing all the arguments passed in and the default
  870. ;;; for the argument the entry point is for.  The last entry point calls the
  871. ;;; real body of the function.  In the presence of supplied-p args and other
  872. ;;; hair, things are more complicated.  In general, there is a distinct
  873. ;;; internal function that takes the supplied-p args as parameters.  The
  874. ;;; preceding entry point calls this function with NIL filled in for the
  875. ;;; supplied-p args, while the current entry point calls it with T in the
  876. ;;; supplied-p positions.
  877. ;;;
  878. ;;; Note that it is easy to turn a call with a known number of arguments into a
  879. ;;; direct call to the appropriate entry-point function, so functions that are
  880. ;;; compiled together can avoid doing the dispatch.
  881. ;;;
  882. (defstruct (optional-dispatch (:include functional)
  883.                   (:print-function %print-optional-dispatch))
  884.   ;;
  885.   ;; The original parsed argument list, for anyone who cares.
  886.   (arglist nil :type list)
  887.   ;;
  888.   ;; True if &allow-other-keys was supplied.
  889.   (allowp nil :type boolean)
  890.   ;;
  891.   ;; True if &key was specified.  (Doesn't necessarily mean that there are any
  892.   ;; keyword arguments...)
  893.   (keyp nil :type boolean)
  894.   ;;
  895.   ;; The number of required arguments.  This is the smallest legal number of
  896.   ;; arguments.
  897.   (min-args 0 :type unsigned-byte)
  898.   ;;
  899.   ;; The total number of required and optional arguments.  Args at positions >=
  900.   ;; to this are rest, key or illegal args.
  901.   (max-args 0 :type unsigned-byte)
  902.   ;;
  903.   ;; List of the Lambdas which are the entry points for non-rest, non-key
  904.   ;; calls.  The entry for Min-Args is first, Min-Args+1 second, ... Max-Args
  905.   ;; last.  The last entry-point always calls the main entry; in simple cases
  906.   ;; it may be the main entry.
  907.   (entry-points nil :type list)
  908.   ;;
  909.   ;; An entry point which takes Max-Args fixed arguments followed by an
  910.   ;; argument context pointer and an argument count.  This entry point deals
  911.   ;; with listifying rest args and parsing keywords.  This is null when extra
  912.   ;; arguments aren't legal.  
  913.   (more-entry nil :type (or clambda null))
  914.   ;;
  915.   ;; The main entry-point into the function, which takes all arguments
  916.   ;; including keywords as fixed arguments.  The format of the arguments must
  917.   ;; be determined by examining the arglist.  This may be used by callers that
  918.   ;; supply at least Max-Args arguments and know what they are doing.
  919.   (main-entry nil :type (or clambda null)))
  920.  
  921.  
  922. (defprinter optional-dispatch
  923.   name
  924.   (type :test (not (eq type *universal-type*)))
  925.   (where-from :test (not (eq where-from :assumed)))
  926.   arglist
  927.   allowp
  928.   keyp
  929.   min-args
  930.   max-args
  931.   (entry-points :test entry-points)
  932.   (more-entry :test more-entry)
  933.   main-entry)
  934.  
  935.  
  936. ;;; The Arg-Info structure allows us to tack various information onto
  937. ;;; Lambda-Vars during IR1 conversion.  If we use one of these things, then the
  938. ;;; var will have to be massaged a bit before it is simple and lexical.
  939. ;;;
  940. (defstruct (arg-info (:print-function %print-arg-info))
  941.   ;;
  942.   ;; True if this arg is to be specially bound.
  943.   (specialp nil :type boolean)
  944.   ;;
  945.   ;; The kind of argument being described.  Required args only have arg
  946.   ;; info structures if they are special.
  947.   (kind (required-argument) :type (member :required :optional :keyword :rest))
  948.   ;;
  949.   ;; If true, the Var for supplied-p variable of a keyword or optional arg.
  950.   ;; This is true for keywords with non-constant defaults even when there is no
  951.   ;; user-specified supplied-p var.
  952.   (supplied-p nil :type (or lambda-var null))
  953.   ;;
  954.   ;; The default for a keyword or optional, represented as the original
  955.   ;; Lisp code.  This is set to NIL in keyword arguments that are defaulted
  956.   ;; using the supplied-p arg.
  957.   (default nil :type t)
  958.   ;;
  959.   ;; The actual keyword for a keyword argument.
  960.   (keyword nil :type (or keyword null)))
  961.  
  962. (defprinter arg-info
  963.   (specialp :test specialp)
  964.   kind
  965.   (supplied-p :test supplied-p)
  966.   (default :test default)
  967.   (keyword :test keyword))
  968.  
  969.  
  970. ;;; The Lambda-Var structure represents a lexical lambda variable.  This
  971. ;;; structure is also used during IR1 conversion to describe lambda arguments
  972. ;;; which may ultimately turn out not to be simple and lexical.
  973. ;;;
  974. ;;; Lambda-Vars with no Refs are considered to be deleted; environment analysis
  975. ;;; isn't done on these variables, so the back end must check for and ignore
  976. ;;; unreferenced variables.  Note that a deleted lambda-var may have sets; in
  977. ;;; this case the back end is still responsible for propagating the Set-Value
  978. ;;; to the set's Cont.
  979. ;;;
  980. (defstruct (lambda-var (:include basic-var)
  981.                (:print-function %print-lambda-var))
  982.   ;;
  983.   ;; True if this variable has been declared Ignore.
  984.   (ignorep nil :type boolean)
  985.   ;;
  986.   ;; The Lambda that this var belongs to.  This may be null when we are
  987.   ;; building a lambda during IR1 conversion.
  988.   (home nil :type (or null clambda))
  989.   ;;
  990.   ;; This is set by environment analysis if it chooses an indirect (value cell)
  991.   ;; representation for this variable because it is both set and closed over.
  992.   (indirect nil :type boolean)
  993.   ;;
  994.   ;; The following two slots are only meaningful during IR1 conversion of hairy
  995.   ;; lambda vars:
  996.   ;;
  997.   ;; The Arg-Info structure which holds information obtained from &keyword
  998.   ;; parsing.
  999.   (arg-info nil :type (or arg-info null))
  1000.   ;;
  1001.   ;; If true, the Global-Var structure for the special variable which is to be
  1002.   ;; bound to the value of this argument.
  1003.   (specvar nil :type (or global-var null))
  1004.   ;;
  1005.   ;; Set of the CONSTRAINTs on this variable.  Used by constraint
  1006.   ;; propagation.  This is left null by the lambda pre-pass if it determine
  1007.   ;; that this is a set closure variable, and is thus not a good subject for
  1008.   ;; flow analysis.
  1009.   (constraints nil :type (or sset null)))
  1010.  
  1011. (defprinter lambda-var
  1012.   name
  1013.   (type :test (not (eq type *universal-type*)))
  1014.   (where-from :test (not (eq where-from :assumed)))
  1015.   (ignorep :test ignorep)
  1016.   (arg-info :test arg-info)
  1017.   (specvar :test specvar))
  1018.  
  1019.  
  1020. ;;;; Basic node types:
  1021.  
  1022. ;;; A Ref represents a reference to a leaf.  Ref-Reoptimize is initially (and
  1023. ;;; forever) NIL, since Refs don't receive any values and don't have any IR1
  1024. ;;; optimizer.
  1025. ;;;
  1026. (defstruct (ref
  1027.         (:include node (:reoptimize nil))
  1028.         (:constructor really-make-ref (derived-type leaf inlinep))
  1029.         (:print-function %print-ref))
  1030.   ;;
  1031.   ;; The leaf referenced.
  1032.   (leaf nil :type leaf)
  1033.   ;;
  1034.   ;; For a function variable, indicates the legality of coding inline.  Nil,
  1035.   ;; means that there is no relevent declaration so we can do whatever we want.
  1036.   (inlinep nil :type inlinep))
  1037.  
  1038. (defprinter ref
  1039.   leaf
  1040.   (inlinep :test inlinep))
  1041.  
  1042.  
  1043. ;;; Naturally, the IF node always appears at the end of a block.  Node-Cont is
  1044. ;;; a dummy continuation, and is there only to keep people happy.
  1045. ;;;
  1046. (defstruct (cif (:include node)
  1047.         (:print-function %print-if)
  1048.         (:conc-name if-)
  1049.         (:predicate if-p)
  1050.         (:constructor make-if)
  1051.         (:copier copy-if))
  1052.   ;;
  1053.   ;; Continuation for the predicate.
  1054.   (test (required-argument) :type continuation)
  1055.   ;;
  1056.   ;; The blocks that we execute next in true and false case, respectively (may
  1057.   ;; be the same.)
  1058.   (consequent (required-argument) :type cblock)
  1059.   (alternative (required-argument) :type cblock))
  1060.  
  1061. (defprinter if
  1062.   (test :prin1 (continuation-use test))
  1063.   consequent
  1064.   alternative)
  1065.  
  1066.  
  1067. (defstruct (cset (:include node
  1068.                (:derived-type *universal-type*))
  1069.          (:print-function %print-set)
  1070.          (:conc-name set-)
  1071.          (:predicate set-p)
  1072.          (:constructor make-set)
  1073.          (:copier copy-set))
  1074.   ;;
  1075.   ;; Descriptor for the variable set.
  1076.   (var (required-argument) :type basic-var)
  1077.   ;;
  1078.   ;; Continuation for the value form.
  1079.   (value (required-argument) :type continuation))
  1080.  
  1081. (defprinter set
  1082.   var
  1083.   (value :prin1 (continuation-use value)))
  1084.  
  1085.  
  1086. ;;; The Basic-Combination structure is used to represent both normal and
  1087. ;;; multiple value combinations.  In a local function call, this node appears
  1088. ;;; at the end of its block and the body of the called function appears as the
  1089. ;;; successor.  The NODE-CONT remains the continuation which receives the
  1090. ;;; value of the call.
  1091. ;;;
  1092. (defstruct (basic-combination (:include node))
  1093.   ;;
  1094.   ;; Continuation for the function.
  1095.   (fun (required-argument) :type continuation)
  1096.   ;;
  1097.   ;; List of continuations for the args.  In a local call, an argument
  1098.   ;; continuation may be replaced with NIL to indicate that the corresponding
  1099.   ;; variable is unreferenced, and thus no argument value need be passed.
  1100.   (args nil :type list)
  1101.   ;;
  1102.   ;; The kind of function call being made.  :Full is a standard call, with the
  1103.   ;; function being determined at run time.  :Local is used when we are calling
  1104.   ;; a function known at compile time.  The IR1 for the called function is
  1105.   ;; spliced into the flow graph for the caller.  Calls to known global
  1106.   ;; functions are represented by storing the Function-Info for the function in
  1107.   ;; this slot.
  1108.   (kind :full :type (or (member :full :local) function-info))
  1109.   ;;
  1110.   ;; Some kind of information attached to this node by the back end.
  1111.   (info nil))
  1112.  
  1113.  
  1114. ;;; The Combination node represents all normal function calls, including
  1115. ;;; FUNCALL.  This is distinct from Basic-Combination so that an MV-Combination
  1116. ;;; isn't Combination-P.
  1117. ;;;
  1118. (defstruct (combination (:include basic-combination)
  1119.             (:constructor really-make-combination (fun))
  1120.             (:print-function %print-combination)))
  1121.  
  1122. (defprinter combination
  1123.   (fun :prin1 (continuation-use fun))
  1124.   (args :prin1 (mapcar #'(lambda (x)
  1125.                (if x
  1126.                    (continuation-use x)
  1127.                    "<deleted>"))
  1128.                args)))
  1129.  
  1130.  
  1131. ;;; An MV-Combination is to Multiple-Value-Call as a Combination is to Funcall.
  1132. ;;; This is used to implement all the multiple-value receiving forms.
  1133. ;;;
  1134. (defstruct (mv-combination (:include basic-combination)
  1135.                (:constructor make-mv-combination (fun))
  1136.                (:print-function %print-mv-combination)))
  1137.  
  1138. (defprinter mv-combination
  1139.   (fun :prin1 (continuation-use fun))
  1140.   (args :prin1 (mapcar #'continuation-use args)))
  1141.  
  1142.  
  1143. ;;; The Bind node marks the beginning of a lambda body and represents the
  1144. ;;; creation and initialization of the variables.
  1145. ;;;
  1146. (defstruct (bind (:include node)
  1147.          (:print-function %print-bind))
  1148.   ;;
  1149.   ;; The lambda we are binding variables for.  Null when we are creating the
  1150.   ;; Lambda during IR1 translation.
  1151.   (lambda nil :type (or clambda null)))
  1152.  
  1153. (defprinter bind
  1154.   lambda)
  1155.  
  1156.  
  1157. ;;; The Return node marks the end of a lambda body.  It collects the return
  1158. ;;; values and represents the control transfer on return.  This is also where
  1159. ;;; we stick information used for Tail-Set type inference.
  1160. ;;;
  1161. (defstruct (creturn (:include node)
  1162.             (:print-function %print-return)
  1163.             (:conc-name return-)
  1164.             (:predicate return-p)
  1165.             (:constructor make-return)
  1166.             (:copier copy-return))
  1167.   ;;
  1168.   ;; The lambda we are returing from.  Null temporarily during ir1tran.
  1169.   (lambda nil :type (or clambda null))
  1170.   ;;
  1171.   ;; The continuation which yields the value of the lambda.
  1172.   (result (required-argument) :type continuation)
  1173.   ;;
  1174.   ;; The union of the node-derived-type of all uses of the result other than by
  1175.   ;; a local call, intersected with the result's asserted-type.  If there are
  1176.   ;; no non-call uses, this is *empty-type*.
  1177.   (result-type *wild-type* :type ctype))
  1178.  
  1179.  
  1180. (defprinter return
  1181.   lambda
  1182.   result-type)
  1183.  
  1184.  
  1185. ;;;; Non-local exit support:
  1186. ;;;
  1187. ;;;    In IR1, we insert special nodes to mark potentially non-local lexical
  1188. ;;; exits.
  1189.  
  1190.  
  1191. ;;; The Entry node serves to mark the start of the dynamic extent of a lexical
  1192. ;;; exit.  It is the mess-up node for the corresponding :Entry cleanup.
  1193. ;;;
  1194. (defstruct (entry (:include node)
  1195.           (:print-function %print-entry))
  1196.   ;;
  1197.   ;; All of the Exit nodes for potential non-local exits to this point.
  1198.   (exits nil :type list)
  1199.   ;;
  1200.   ;; The cleanup for this entry.  Null only temporarily.
  1201.   (cleanup nil :type (or cleanup null)))
  1202.  
  1203. (defprinter entry)
  1204.  
  1205.  
  1206. ;;; The Exit node marks the place at which exit code would be emitted, if
  1207. ;;; necessary.  This is interposed between the uses of the exit continuation
  1208. ;;; and the exit continuation's DEST.  Instead of using the returned value
  1209. ;;; being delivered directly to the exit continuation, it is delivered to our
  1210. ;;; Value continuation.  The original exit continuation is the exit node's
  1211. ;;; CONT.
  1212. ;;;
  1213. (defstruct (exit (:include node)
  1214.          (:print-function %print-exit))
  1215.   ;;
  1216.   ;; The Entry node that this is an exit for.  If null, this is a degenerate
  1217.   ;; exit.  A degenerate exit is used to "fill" an empty block (which isn't
  1218.   ;; allowed in IR1.)  In a degenerate exit, Value is always also null.
  1219.   (entry nil :type (or entry null))
  1220.   ;;
  1221.   ;; The continuation yeilding the value we are to exit with.  If NIL, then no
  1222.   ;; value is desired (as in GO).
  1223.   (value nil :type (or continuation null)))
  1224.  
  1225. (defprinter exit
  1226.   (entry :test entry)
  1227.   (value :test value))
  1228.  
  1229.  
  1230. ;;;; Miscellaneous IR1 structures:
  1231.  
  1232. (defstruct (undefined-warning
  1233.         (:print-function
  1234.          (lambda (s stream d)
  1235.            (declare (ignore d))
  1236.            (format stream "#<Delayed-Warning ~S>"
  1237.                (undefined-warning-name s)))))
  1238.   ;;
  1239.   ;; The name of the unknown thing.
  1240.   (name nil :type (or symbol list))
  1241.   ;;
  1242.   ;; The kind of reference to Name.
  1243.   (kind (required-argument) :type (member :function :type :variable))
  1244.   ;;
  1245.   ;; The number of times this thing was used.
  1246.   (count 0 :type unsigned-byte)
  1247.   ;;
  1248.   ;; A list of COMPILER-ERROR-CONTEXT structures describing places where this
  1249.   ;; thing was used.  Note that we only record the first
  1250.   ;; *UNDEFINED-WARNING-LIMIT* calls.
  1251.   (warnings () :type list))
  1252.  
  1253.  
  1254. ;;;; Freeze some structure types to speed type testing:
  1255.  
  1256. (declaim (freeze-type node leaf lexenv continuation cblock component cleanup
  1257.               environment tail-set nlx-info))
  1258.